#include "runedata.h"
#include "buffs.h"
#include "symbol.h"
#include "creature.h"
#include "random.h"
#include "message.h"

std::vector< std::pair< std::string, bool > > Rune::_runeNames;
std::vector< Colour >      Rune::_runeColours;

Rune::Rune( int number )
{
    _number = number;
}

bool Rune::ItemType( uint* type ) const
{
    *type |= WIELDABLE_1H;
    return true;
}

bool Rune::ItemCategory( uint* category ) const
{
    *category = RUNE;
    return true;
}

bool Rune::ItemWeight( uint* weight ) const
{
    *weight += 5;
    return true;
}

bool Rune::OnEaten( Creature* c )
{
    Bank().Manipulation( MANIPULATION_EAT_OTHER, c, this );
    Destroy();
    return true;
}

void Rune::RandomiseRuneNames()
{
    _runeColours.clear();
    _runeNames.clear();

    _runeColours.push_back( Colour( 255, 255, 255 ) );
    _runeColours.push_back( Colour( 255, 255, 128 ) );
    _runeColours.push_back( Colour( 255, 128, 255 ) );
    _runeColours.push_back( Colour( 128, 255, 255 ) );
    _runeColours.push_back( Colour( 255, 128, 128 ) );
    _runeColours.push_back( Colour( 128, 255, 128 ) );
    _runeColours.push_back( Colour( 128, 128, 255 ) );
    _runeColours.push_back( Colour( 128, 128, 128 ) );
    _runeColours.push_back( Colour( 255, 255,   0 ) );
    _runeColours.push_back( Colour( 255,   0, 255 ) );
    _runeColours.push_back( Colour(   0, 255, 255 ) );
    _runeColours.push_back( Colour( 255,   0,   0 ) );
    _runeColours.push_back( Colour(   0, 255,   0 ) );
    _runeColours.push_back( Colour(   0,   0, 255 ) );
    _runeColours.push_back( Colour( 255, 128,   0 ) );
    _runeColours.push_back( Colour( 128, 255,   0 ) );
    _runeColours.push_back( Colour( 255,   0, 128 ) );
    _runeColours.push_back( Colour( 128,   0, 255 ) );
    _runeColours.push_back( Colour(   0, 255, 128 ) );
    _runeColours.push_back( Colour(   0, 128, 255 ) );
    _runeColours.push_back( Colour(   0, 128, 128 ) );
    _runeColours.push_back( Colour( 0,   128, 128 ) );
    _runeColours.push_back( Colour( 128, 128,   0 ) );

    _runeNames.push_back( std::make_pair( "Alb", true ) );
    _runeNames.push_back( std::make_pair( "Bayn", false ) );
    _runeNames.push_back( std::make_pair( "Carn", false ) );
    _runeNames.push_back( std::make_pair( "Dar", false ) );
    _runeNames.push_back( std::make_pair( "Ebur", true ) );
    _runeNames.push_back( std::make_pair( "Faik", false ) );
    _runeNames.push_back( std::make_pair( "Glom", false ) );
    _runeNames.push_back( std::make_pair( "Hjad", false ) );
    _runeNames.push_back( std::make_pair( "Ilk", true ) );
    _runeNames.push_back( std::make_pair( "Jaum", false ) );
    _runeNames.push_back( std::make_pair( "Kair", false ) );
    _runeNames.push_back( std::make_pair( "Lach", false ) );
    _runeNames.push_back( std::make_pair( "Mirk", false ) );
    _runeNames.push_back( std::make_pair( "Naam", false ) );
    _runeNames.push_back( std::make_pair( "Ora", true ) );
    _runeNames.push_back( std::make_pair( "Poen", false ) );
    _runeNames.push_back( std::make_pair( "Qua", false ) );
    _runeNames.push_back( std::make_pair( "Rath", false ) );
    _runeNames.push_back( std::make_pair( "Shud", false ) );
    _runeNames.push_back( std::make_pair( "Tirl", false ) );
    _runeNames.push_back( std::make_pair( "Ure", true ) );
    _runeNames.push_back( std::make_pair( "Vyre", false ) );
    _runeNames.push_back( std::make_pair( "Ydurn", true ) );
    _runeNames.push_back( std::make_pair( "Zad", false ) );

    for ( std::size_t i = 0; i < _runeColours.size() - 1; ++i )
        std::swap( _runeColours[ i ], _runeColours[ i + Random::Int( _runeColours.size() - i ) ] );
    for ( std::size_t i = 0; i < _runeNames.size() - 1; ++i )
        std::swap( _runeNames[ i ], _runeNames[ i + Random::Int( _runeNames.size() - i ) ] );
}

bool Rune::Name( std::string* name, bool* plural, uint article ) const
{
    if ( name->empty() && article == ARTICLE_INDEFINITE )
        *name += _runeNames[ _number ].second ? "an " : "a ";
    *name += _runeNames[ _number ].first + " ";
    if ( article == ARTICLE_PLURAL )
        *name += "runes";
    else
        *name += "rune";
    return true;
}

bool Rune::ItemSymbol( IO::Sym* symbol ) const
{
    symbol->first = '*';
    symbol->second = _runeColours[ _number ];
    return true;
}

bool FireRune::Flammable( uint* flammableType ) const
{
    *flammableType |= BIFlammable::FLAMMABLE_BURN_INDEFINITE | BIFlammable::FLAMMABLE_DESTROY;
    return true;
}